package Control;

import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import Model.Wereld;
import View.Overview;

@SuppressWarnings("serial")
public class Apl extends JFrame
{
	private Overview view;
	private FrameListener frameListener;
	private Wereld wereld;
	public Apl(Wereld wereld)
	{
		this.wereld = wereld;
		//wereld.addRadar(xPos, yPos, withZicht, heightZicht, withManouvreerbaar, heightManouvreerbaar)
		wereld.addRadar(20 , 700, 150, 150, 400, 500);
		wereld.addRadar(275, 650, 100, 100, 300, 300);
		wereld.addRadar(450, 660, 50 , 50 , 200, 200);
		wereld.addRadar(600, 525, 100, 100, 250, 250);
		wereld.addRadar(600, 360, 75 , 75 , 250, 250);
		wereld.addRadar(420, 320, 100, 100, 250, 250);
		wereld.addRadar(200, 250, 100, 100, 250, 250);
		wereld.addRadar(230, 65 , 75 , 75 , 220, 220);
		wereld.addRadar(400, 50 , 50 , 50 , 150, 150);
		wereld.addRadar(630, 40 , 40 , 40 , 350, 100);
		
		addFocusListener(new FocusAdapter() {
			public void focusLost(FocusEvent e) {
				System.out.println("Lost");
				requestFocus();
			    }
			});
		
		
		view = new Overview(wereld);
		setSize(new Dimension(800,800));
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setResizable(true);
		setTitle("Helicoptergame Saxion feb 2011");
		setSize(800, 800);
		KeyControl keyControl = new KeyControl(wereld);
		addKeyListener(keyControl);
		frameListener = new FrameListener();
		addComponentListener(frameListener);
		setContentPane(view);
		this.setFocusable(true);
	}

	class FrameListener implements ComponentListener
	{
		public void componentHidden(ComponentEvent e) {

		}
		public void componentMoved(ComponentEvent e) {

		}
		public void componentResized(ComponentEvent e) {
			if(getBounds().width > getBounds().height)
			{
				setSize(getBounds().width,getBounds().width);
			}
			if(getBounds().width < getBounds().height)
			{
				setSize(getBounds().height, getBounds().height);
			}
		}
		public void componentShown(ComponentEvent e) {

		}
	}
	
	
}
